package ans.p830;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * #      830
 * 名称   较大分组的位置
 * 链接   https://leetcode-cn.com/problems/positions-of-large-groups
 * 题解   [546](https://leetcode-cn.com/problems/positions-of-large-groups/solution)
 * 通过率 54.3%
 * 难道   简单
 */

public class Solution {
    public List<List<Integer>> largeGroupPositions(String s) {
        int freq = 0;
        Character prev = null;
        List<List<Integer>> ans = new LinkedList<>();
        for (int i = 0; i <= s.length(); i++) {
            Character c = i < s.length() ? s.charAt(i) : null;
            if (prev != c) {
                if (freq >= 3) {
                    ans.add(Arrays.asList(i - freq , i - 1));
                }
                freq = 0;
            }
            freq++;

            prev = c;
        }
        return ans;
    }
}